package org.brisling.oa;

import java.util.List;

import org.brisling.oa.domain.OACarApply;
import org.brisling.oa.domain.OAConferenceroomApply;
import org.brisling.oa.domain.OADrugPurchase;
import org.brisling.oa.domain.OAEquipmentOverhaul;
import org.brisling.oa.domain.OAEquipmentPurchase;
import org.brisling.oa.domain.OAEquipmentRepaire;
import org.brisling.oa.domain.OALogisticsPurchaseOver;
import org.brisling.oa.domain.OATempDrugPurchase;
import org.brisling.oa.queryService.QueryOACarApplyService;
import org.brisling.oa.queryService.QueryOAConferenceroomApplyService;
import org.brisling.oa.queryService.QueryOADrugPurchaseService;
import org.brisling.oa.queryService.QueryOAEquipmentOverhaulService;
import org.brisling.oa.queryService.QueryOAEquipmentPurchaseService;
import org.brisling.oa.queryService.QueryOAEquipmentRepaireService;
import org.brisling.oa.queryService.QueryOALogisticsPurchaseOverService;
import org.brisling.oa.queryService.QueryOATempDrugPurchaseService;
import org.brisling.oa.service.OACarApplyService;
import org.brisling.oa.service.OAConferenceroomApplyService;
import org.brisling.oa.service.OADrugPurchaseService;
import org.brisling.oa.service.OAEquipmentOverhaulService;
import org.brisling.oa.service.OAEquipmentPurchaseService;
import org.brisling.oa.service.OAEquipmentRepaireService;
import org.brisling.oa.service.OALogisticsPurchaseOverService;
import org.brisling.oa.service.OATempDrugPurchaseService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath*:config/applicationContext.xml",
						"classpath*:config/sysmanContext.xml"})
public class testdelRbs {

	@Autowired
	private QueryOADrugPurchaseService qryDrugPurchaseService;
	@Autowired
	private OADrugPurchaseService drugPurchaseService;
	@Autowired
	private OACarApplyService carApplySer;
	@Autowired
	private QueryOACarApplyService qryCarApplySer;
	@Autowired
	private OAEquipmentPurchaseService equipmentPurchaseSer;
	@Autowired
	private QueryOAEquipmentPurchaseService qryequipmentPurchase;
	@Autowired
	private OAConferenceroomApplyService conferenceroomApplySer;
	@Autowired
	private QueryOAConferenceroomApplyService qryOaConferenceroomApply;
	@Autowired
	private QueryOATempDrugPurchaseService qryOaTempDrugPurchaseSer;
	@Autowired
	private OATempDrugPurchaseService tempDrugPurchaseSer;
	@Autowired
	private OAEquipmentOverhaulService equipmentOverhaulService;
	@Autowired
	private QueryOAEquipmentOverhaulService qryEquipmentOverhaulService;
	@Autowired
	private OAEquipmentRepaireService equipmentRepaireService;
	@Autowired
	private QueryOAEquipmentRepaireService qryEquipmentRepaireService;
	@Autowired
	private OALogisticsPurchaseOverService logisticsPurchaseOverService;
	@Autowired //testForUpdate
	private QueryOALogisticsPurchaseOverService qryLogisticsPurchaseOverService;

	@Test
	public void test() {
		delLogOver();
	}
	
	private void delLogOver(){
//		String sql = "select * from oa_logistics_purchaseover";
//		List<OALogisticsPurchaseOver> list = qryLogisticsPurchaseOverService.getAllList(sql);
//		for(OALogisticsPurchaseOver a:list){
//			if(a.getName() != null && a.getName().equals("testForUpdate")){
//				System.out.println(a.getName() + ", " + a.getApply_deptname());
//				logisticsPurchaseOverService.delRow(a.getId(), null);
//			}
//		}
	}
	
	private void delDrugP(){
		String sql = "select * from oa_drug_purchases";
		List<OADrugPurchase> list = qryDrugPurchaseService.getAllList(sql);
		for(OADrugPurchase a:list){
			if(!a.getApply_deptname().equals("院外科室")){
				System.out.println(a.getName() + ", " + a.getApply_deptname());
				drugPurchaseService.del(a.getId());
			}
		}
	}

	private void delEquOve(){
		String sql = "select * from oa_equipment_overhaul";
		List<OAEquipmentOverhaul> list = qryEquipmentOverhaulService.getAllList(sql);
		for(OAEquipmentOverhaul a:list){
			System.out.println(a.getName() + ", " + a.getApply_deptname() + ", " + a.getId());
			equipmentOverhaulService.del(a.getId());
		}
	}

	private void delEquRep(){
		String sql = "select * from oa_equipment_repaires";
		List<OAEquipmentRepaire> list = qryEquipmentRepaireService.getAllList(sql);
		for(OAEquipmentRepaire a:list){
			System.out.println(a.getName() + ", " + a.getApply_deptname() + ", " + a.getId());
			equipmentRepaireService.del(a.getId());
		}
	}
	
	private void delTempD(){
		String sql = "select * from oa_tempdrug_purchases where id <> 68";
		List<OATempDrugPurchase> list = qryOaTempDrugPurchaseSer.getAllList(sql);
		for(OATempDrugPurchase a:list){
			System.out.println(a.getName() + ", " + a.getApply_deptname() + ", " + a.getId());
			tempDrugPurchaseSer.del(a.getId());
		}
	}
	private void delCarApp(){
		String sql = "select * from oa_car_apply";
		List<OACarApply> list = qryCarApplySer.getAllList(sql);
		for(OACarApply a:list){
			if(a.getApply_deptname().equals("未在岗人员")){
				System.out.println(a.getApply_name() + ", " + a.getApply_deptname());
				carApplySer.del(a.getId());
			}
		}
	}
	private void delEquP(){
		String sql = "select * from oa_equipment_purchases";
		List<OAEquipmentPurchase> list = qryequipmentPurchase.getAllList(sql);
		for(OAEquipmentPurchase a:list){
			if(a.getApply_deptname().equals("神经内科")){
				System.out.println(a.getApply_name() + ", " + a.getApply_deptname());
				equipmentPurchaseSer.del(a.getId());
			}
		}
	}

	private void delconRoom(){
		String sql = "select * from oa_conferenceroom_apply";
		List<OAConferenceroomApply> list = qryOaConferenceroomApply.getAllList(sql);
		for(OAConferenceroomApply a:list){
			if(a.getDept_content() == null || (!a.getDept_content().equals("同意使用大会堂。")) && a.getApply_deptname().equals("办公室")){
				System.out.println(a.getApply_name() + ", " + a.getApply_deptname() + ", " + a.getDept_content() + ", " + a.getApply_deptname());
				conferenceroomApplySer.del(a.getId());
			}
		}
	}
}
